<html>
<HEAD>
<script language="javascript"> 
<!--
var backup_window = null;
var state = 'none'; 

function showhide(layer_ref) { 

if (state == 'block') { 
state = 'none'; 
} 
else { 
state = 'block'; 
} 
if (document.all) { //IS IE 4 or 5 (or 6 beta) 
eval( "document.all." + layer_ref + ".style.display = state"); 
} 
if (document.layers) { //IS NETSCAPE 4 or below 
document.layers[layer_ref].display = state; 
} 
if (document.getElementById &&!document.all) { 
hza = document.getElementById(layer_ref); 
hza.style.display = state; 
} 
} 

//-->
</SCRIPT>
</HEAD>
<body>
<DIV style="font-family:Arial;width=90%">
<?php include("database_inc.php"); ?>
<?php 
$caller_table_name = "Caller";
$tables_file = "data_tables.txt";
error_reporting('IGNORE_REPEATED_ERRORS');

    $client_reference_number = $_GET["client_reference_number"]; 
    echo "Purging caller reference number: ".$client_reference_number."<BR>";

    mysql_connect ($db_conn_address, $db_conn_username, $db_conn_password) or die ('Error: ' . mysql_error());
    mysql_select_db($db_QA_database);

    $need_count = 0;
    $agency_count = 0;
    if (strlen($client_reference_number)>0) {

	$handle = @fopen($tables_file, "r");
	//echo "Tables file opened: ".$tables_file." with handle ".$handle."<BR>";
	if ($handle) {
	        $source = null;
	        $buftok[] = null;
		while (!feof($handle)){
			$bufferin = fgets($handle);
	                $bufferin = trim($bufferin);
	                if(strlen(trim($bufferin))>0){
			    $table_name = mysql_real_escape_string($bufferin);
			    if (substr_count($bufferin,$caller_table_name)>0){
		                    $query_string = "DELETE FROM ".$table_name." WHERE REFERENCE_NUMBER=".$client_reference_number.";";
		            }else{
		                    $query_string = "DELETE FROM ".$table_name." WHERE CALLER_REFERENCE=".$client_reference_number.";";
			    }
	                    $select_results = mysql_query($query_string);
			    //echo $query_string."<BR>";
	                }
		}
	
	     fclose($handle);   
	}

	 echo "Client Record ".$client_reference_number." has been removed.<BR>";
    } else {
	 echo "There was an error purging the last record (".$client_reference_number.").  Please use the feedback link below to report it.<BR>";
    } 


?><BR>

<BR>

<div id="input" style="display:block;border:thin solid black;background-color: #AAFFAA;width=40%">
<p><a href="newinput.php"> Enter Another Call</a></p> 
</div>


<BR>
 
<div id="exit" style="display:block;border:thin solid black;background-color: #FFAAAA;width=40%">
<p><a href="#" onclick="showhide('thanks');backup_window=(window.open('./backup_data.php','BackupWindow','width=50,height=50,toolbar=0,menubar=0,status=0,scrollbars=0,resizable=1')).blur();"> Done Entering Calls </a></p>
</div>

<BR><BR>
<div id="thanks" style="display:none;border:thin solid black;background-color: #EEEEEE;width=30%">
<p>Thank You!  Please close the window.</p>
</div>

<BR><BR>
<A href="http://211qa.uservoice.com/pages/34599-general?lang=en&utm_campaign=Widgets&utm_content=tab-widget&utm_medium=widget&utm_source=211qa.uservoice.com" target="_Top">click here to visit the feedback forum where you can provide bug reports, enhancement requests and support questions!</A>


</DIV>
</body>
</html>